﻿using Basic.FormLocalEvent.Model;
using WeDonekRpc.CacheClient.Interface;
using WeDonekRpc.Client.Attr;
using WeDonekRpc.Client.Interface;

namespace Basic.FormLocalEvent.Form
{
    [LocalEventName("Enable", "Stop")]
    internal class ClearCache : IEventHandler<FormEvent>
    {
        private readonly ICacheController _Cache;

        public ClearCache ( ICacheController cache )
        {
            this._Cache = cache;
        }

        public void HandleEvent ( FormEvent data, string eventName )
        {
            if ( data.Form.FormType == FormRemoteModel.FormType.物理表单 )
            {
                string key = "PhyQueryBody_" + data.Form.Id;
                _ = this._Cache.Remove(key);
            }
            else if ( data.Form.FormType == FormRemoteModel.FormType.视图 )
            {
                string key = "FormViewBody_" + data.Form.Id;
                _ = this._Cache.Remove(key);
            }
            else
            {
                string key = string.Concat("FormBody_", data.Form.Id);
                _ = this._Cache.Remove(key);
                key = string.Concat("FormStuct_", data.Form.Id);
                _ = this._Cache.Remove(key);
                key = string.Concat("FormCol_", data.Form.Id);
                _ = this._Cache.Remove(key);
            }

        }
    }
}